﻿<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>黑马面面管理系统</title>
    <meta name="description" content="AdminLTE2定制版">
    <meta name="keywords" content="AdminLTE2定制版">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../element-ui/lib/theme-chalk/index.css">

    <script src="../js/vue.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script src="../js/getParameter.js"></script>
    <script src="../element-ui/lib/index.js"></script>

</head>
<body>
    <div id="frameContent" class="content-wrapper" style="margin-left:0px;">
        <!-- 内容头部 -->
        <section class="content-header">
            <h1>题库管理
                <small>题目的选项</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="all-admin-index.html"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="all-order-manage-list.html">题库管理</a></li>
                <li class="active">选项添加及列表</li>
            </ol>
        </section>
        <!--新增或者编辑-->
        <section class="content">
            <div class="panel panel-default">
                <div class="panel-heading">新增/编辑选项</div>
                <el-form :model="formData" ref="addForm" label-width="100px" class="demo-ruleForm">
                    <div class="row data-type" style="margin: 0px">
                        <div class="col-md-2 title">选项内容</div>
                        <div class="col-md-4 data">
                            <input type="text" class="form-control" placeholder="选项内容" v-model="formData.content">
                        </div>
                        <div class="col-md-2 title">选项图片</div>
                        <div class="col-md-4 data">
                            <input type="file" class="form-control" placeholder="请选择" name="picture" >
                        </div>
                        <div class="col-md-2 title">是否正确答案</div>
                        <div class="col-md-4 data">
                            <select class="form-control" v-model="formData.isRight">
                                <option value="1">正确答案</option>
                                <option value="0">错误选项</option>
                            </select>
                        </div>
                    </div>
                    <div class="box-tools text-center">
                        <button type="button" @click="handleAddOrEdit()" class="btn bg-maroon">保存/编辑</button>
                        <button type="button" class="btn bg-default" onclick="history.back(-1);">返回</button>
                    </div>
                </el-form>
            </div>
        </section>
        <!--问题选项列表-->
        <section class="content">
            <!-- .box-body -->
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">选项列表</h3>
                </div>

                <div class="box-body">
                    <!-- 数据表格 -->
                    <div class="table-box">
                        <!--工具栏-->
                        <div class="pull-left">
                            <div class="form-group form-inline">
                                <div class="btn-group">
                                    <button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新</button>
                                </div>
                            </div>
                        </div>
                        <div class="box-tools pull-right">
                            <div class="has-feedback">
                                <input type="text" class="form-control input-sm" placeholder="搜索">
                                <span class="glyphicon glyphicon-search form-control-feedback"></span>
                            </div>
                        </div>
                        <!--数据列表-->
                        <table class="table table-bordered table-striped table-hover dataTable">
                            <thead>
                            <tr>
                                <td class="tableHeader">选项内容</td>
                                <td class="tableHeader">是否正确答案</td>
                                <td class="tableHeader">操作</td>
                            </tr>
                            </thead>
                            <tbody class="tableBody" >
                            <tr v-for="questionItem in dataList" class="odd" onmouseover="this.className='highlight'" onmouseout="this.className='odd'" >
                                <td>{{questionItem.content}}</td>
                                <td>{{questionItem.isRight=="1"?"正确答案":""}}</td>
                                <td>
                                    <button type="button" class="btn bg-olive btn-xs" @click='handleUpdate(questionItem.id)'>编辑</button>
                                    <button type="button" class="btn bg-olive btn-xs" @click='handleDelete(questionItem.id)'>删除</button>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>
    </div>
    <script>
        //获取问题id
        let questionId = getUrlParam("questionId");
    </script>
    <script>
        new Vue({
            el:"#frameContent",
            data:{
                dataList: [],//当前页要展示的分页列表数据
                formData: {},//表单数据
                isAddOrUpdate:false //是新增还是修改，false表示新增，true表示要修改
            },
            created(){ //vue对象创建完成的回调函数
                this.findAll()
            },
            methods:{

                //查询题目选项方法
                findAll(){
                    axios.get("../store/questionItem/findAll?questionId="+questionId).then(resp=>{
                        if (resp.data.flag){
                            this.dataList=resp.data.data;
                        }else {
                            this.$message.error(resp.data.message);
                        }
                    })
                },
                //重置表单方法
                resetForm(){
                    this.formData={};
                },
                //保存方法
                handleAddOrEdit(){
                    this.formData.questionId=questionId;
                    if (this.formData.id){
                        axios.post("../store/questionItem/edit", this.formData).then(resp => {
                            if (resp.data.flag) {
                                this.findAll();
                                this.isAddOrUpdate=false;
                            } else {
                                this.$message.error(resp.data.message);
                            }
                        })
                    }else {
                        axios.post("../store/questionItem/save", this.formData).then(resp => {
                            if (resp.data.flag) {
                                this.findAll();
                            } else {
                                this.$message.error(resp.data.message);
                            }
                        })
                    }
                },
                //修改方法
                handleUpdate(id){
                    this.resetForm();
                    axios.post("../store/questionItem/findById?id="+id).then(resp=>{
                        if (resp.data.flag){
                            this.formData=resp.data.data;
                            this.isAddOrUpdate=true;
                        }else {
                            this.$message.error(resp.data.message);
                        }
                    })
                },
                //删除方法
                handleDelete(id) {
                    this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        axios.post("../store/questionItem/delete?id="+id).then(resp=>{
                            if (resp.data.flag){
                                this.findAll();
                                this.$message({
                                    type: 'success',
                                    message: '删除成功!'
                                });
                            }else {
                                this.$message.error(this.data.message);
                            }
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
                }
            }
        });
    </script>
</body>

</html>